home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / GSCHAR.C < prev    next >
C/C++ Source or Header  |  1992-03-06  |  19KB  |  633 lines

  1. /* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gschar.c */
  21. /* Character writing operators for Ghostscript library */
  22. #include "gx.h"
  23. #include "memory_.h"
  24. #include "string_.h"
  25. #include "gserrors.h"
  26. #include "gxfixed.h"            /* ditto */
  27. #include "gxarith.h"
  28. #include "gxmatrix.h"
  29. #include "gzstate.h"            /* must precede gzdevice */
  30. #include "gzdevice.h"            /* must precede gxchar */
  31. #include "gxdevmem.h"
  32. #include "gxchar.h"
  33. #include "gxcache.h"
  34. #include "gxfont.h"
  35. #include "gspath.h"
  36. #include "gzpath.h"
  37. #include "gzcolor.h"
  38.  
  39. /* Exported size of enumerator */
  40. const uint gs_show_enum_sizeof = sizeof(gs_show_enum);
  41.  
  42. /* Imported procedures */
  43. extern void gx_set_black(P1(gs_state *));
  44.  
  45. /* Forward declarations */
  46. private int continue_show(P1(gs_show_enum *));
  47. private int continue_show_update(P1(gs_show_enum *));
  48. private int show_setup(P3(gs_show_enum *, gs_state *, char *));
  49. private int stringwidth_setup(P3(gs_show_enum *, gs_state *, char *));
  50.  
  51. /* Print the ctm if debugging */
  52. #define print_ctm(s,pgs)\
  53.   dprintf7("[p]%sctm=[%g %g %g %g %g %g]\n", s,\
  54.        pgs->ctm.xx, pgs->ctm.xy, pgs->ctm.yx, pgs->ctm.yy,\
  55.        pgs->ctm.tx, pgs->ctm.ty)
  56.  
  57. /* ------ String writing operators ------ */
  58.  
  59. /* Setup macros for show operators */
  60. #define setup_show()\
  61.   penum->size = strlen(str)
  62. #define setup_show_n()\
  63.   penum->size = size
  64. #define setup_a()\
  65.   penum->add = 1, penum->ax = ax, penum->ay = ay,\
  66.   penum->slow_show = 1
  67. #define setup_width()\
  68.   penum->wchr = chr, penum->wcx = cx, penum->wcy = cy,\
  69.   penum->slow_show = 1
  70. #define no_chr ~(char_code)0
  71.  
  72. /* show[_n] */
  73. int
  74. gs_show_init(register gs_show_enum *penum,
  75.   gs_state *pgs, char *str)
  76. {    setup_show();
  77.     penum->slow_show = 0;
  78.     return show_setup(penum, pgs, str);
  79. }
  80. int
  81. gs_show_n_init(register gs_show_enum *penum,
  82.   gs_state *pgs, char *str, uint size)
  83. {    setup_show_n();
  84.     penum->slow_show = 0;
  85.     return show_setup(penum, pgs, str);
  86. }
  87.  
  88. /* ashow[_n] */
  89. int
  90. gs_ashow_init(register gs_show_enum *penum,
  91.   gs_state *pgs, floatp ax, floatp ay, char *str)
  92. {    int code;
  93.     setup_show();
  94.     code = show_setup(penum, pgs, str);
  95.     setup_a();
  96.     return code;
  97. }
  98. int
  99. gs_ashow_n_init(register gs_show_enum *penum,
  100.   gs_state *pgs, floatp ax, floatp ay, char *str, uint size)
  101. {    int code;
  102.     setup_show_n();
  103.     code = show_setup(penum, pgs, str);
  104.     setup_a();
  105.     return code;
  106. }
  107.  
  108. /* widthshow[_n] */
  109. int
  110. gs_widthshow_init(register gs_show_enum *penum,
  111.   gs_state *pgs, floatp cx, floatp cy, char chr, char *str)
  112. {    int code;
  113.     setup_show();
  114.     code = show_setup(penum, pgs, str);
  115.     setup_width();
  116.     return code;
  117. }
  118. int
  119. gs_widthshow_n_init(register gs_show_enum *penum,
  120.   gs_state *pgs, floatp cx, floatp cy, char chr, char *str, uint size)
  121. {    int code;
  122.     setup_show_n();
  123.     code = show_setup(penum, pgs, str);
  124.     setup_width();
  125.     return code;
  126. }
  127.  
  128. /* awidthshow[_n] */
  129. int
  130. gs_awidthshow_init(register gs_show_enum *penum,
  131.   gs_state *pgs, floatp cx, floatp cy, char chr, floatp ax, floatp ay,
  132.   char *str)
  133. {    int code;
  134.     setup_show();
  135.     code = show_setup(penum, pgs, str);
  136.     setup_a();
  137.     setup_width();
  138.     return code;
  139. }
  140. int
  141. gs_awidthshow_n_init(register gs_show_enum *penum,
  142.   gs_state *pgs, floatp cx, floatp cy, char chr, floatp ax, floatp ay,
  143.   char *str, uint size)
  144. {    int code;
  145.     setup_show_n();
  146.     code = show_setup(penum, pgs, str);
  147.     setup_a();
  148.     setup_width();
  149.     return code;
  150. }
  151.  
  152. /* kshow[_n] */
  153. int
  154. gs_kshow_init(register gs_show_enum *penum,
  155.   gs_state *pgs, char *str)
  156. {    int code;
  157.     if ( pgs->font->FontType == ft_composite)
  158.         return_error(gs_error_invalidfont);
  159.     setup_show();
  160.     code = show_setup(penum, pgs, str);
  161.     penum->do_kern = penum->slow_show = 1;
  162.     return code;
  163. }
  164. int
  165. gs_kshow_n_init(register gs_show_enum *penum,
  166.   gs_state *pgs, char *str, uint size)
  167. {    int code;
  168.     if ( pgs->font->FontType == ft_composite)
  169.         return_error(gs_error_invalidfont);
  170.     setup_show_n();
  171.     code = show_setup(penum, pgs, str);
  172.     penum->do_kern = penum->slow_show = 1;
  173.     return code;
  174. }
  175.  
  176. /* ------ Related operators ------ */
  177.  
  178. /* stringwidth[_n] */
  179. int
  180. gs_stringwidth_init(gs_show_enum *penum, gs_state *pgs, char *str)
  181. {    setup_show();
  182.     return stringwidth_setup(penum, pgs, str);
  183. }
  184. int
  185. gs_stringwidth_n_init(gs_show_enum *penum, gs_state *pgs, char *str, uint size)
  186. {    setup_show_n();
  187.     return stringwidth_setup(penum, pgs, str);
  188. }
  189.  
  190. /* Common code for stringwidth[_n] */
  191. private int
  192. stringwidth_setup(gs_show_enum *penum, gs_state *pgs, char *str)
  193. {    int code = show_setup(penum, pgs, str);
  194.     if ( code < 0 ) return_error(code);
  195.     penum->stringwidth_flag = 1;
  196.     /* Do an extra gsave and suppress output */
  197.     if ( (code = gs_gsave(pgs)) < 0 ) return code;
  198.     penum->level = pgs->level;    /* for level check in show_update */
  199.     gx_device_no_output(pgs);
  200.     /* Establish an arbitrary current point. */
  201.     return gx_path_add_point(pgs->path, pgs->ctm.tx_fixed, pgs->ctm.ty_fixed);
  202. }
  203.  
  204. /* charpath[_n] */
  205. int
  206. gs_charpath_init(gs_show_enum *penum, gs_state *pgs,
  207.   char *str, int bool)
  208. {    int code;
  209.     setup_show();
  210.     code = show_setup(penum, pgs, str);
  211.     penum->charpath_flag = (bool ? 2 : 1);
  212.     penum->can_cache = 0;
  213.     return code;
  214. }
  215. int
  216. gs_charpath_n_init(gs_show_enum *penum, gs_state *pgs,
  217.   char *str, uint size, int bool)
  218. {    int code;
  219.     setup_show_n();
  220.     code = show_setup(penum, pgs, str);
  221.     penum->charpath_flag = (bool ? 2 : 1);
  222.     penum->can_cache = 0;
  223.     return code;
  224. }
  225.  
  226. /* ------ Width/cache operators ------ */
  227.  
  228. /* setcachedevice */
  229. int
  230. gs_setcachedevice(register gs_show_enum *penum, gs_state *pgs,
  231.   floatp wx, floatp wy, floatp llx, floatp lly, floatp urx, floatp ury)
  232. {    int code = gs_setcharwidth(penum, pgs, wx, wy);    /* default is don't cache */
  233.     if ( code < 0 ) return code;
  234.     /* See if we want to cache this character. */
  235.     if ( pgs->in_cachedevice )        /* no recursion! */
  236.         return 0;
  237.     pgs->in_cachedevice = 1;    /* disable color/gray/image operators */
  238.     /* We can only use the cache if ctm is unchanged */
  239.     /* (aside from a possible translation), */
  240.     /* and if the extent of the box is non-negative. */
  241.     if ( !penum->can_cache || !pgs->char_tm_valid ||
  242.          llx > urx || lly > ury
  243.        )
  244.         return 0;
  245.        {    gs_font_dir *dir = pgs->font->dir;
  246.         gs_fixed_point cbox_ll, cbox_ur, cdim;
  247.         long iwidth, iheight;
  248.         cached_char *cc;
  249.         gs_fixed_rect clip_box;
  250.         gs_distance_transform2fixed(&pgs->ctm, llx, lly, &cbox_ll);
  251.         gs_distance_transform2fixed(&pgs->ctm, urx, ury, &cbox_ur);
  252.         cdim.x = cbox_ur.x - cbox_ll.x;
  253.         cdim.y = cbox_ur.y - cbox_ll.y;
  254.         if ( cdim.x < 0 ) cdim.x = -cdim.x;
  255.         if ( cdim.y < 0 ) cdim.y = -cdim.y;
  256. #ifdef DEBUG
  257. if ( gs_debug['k'] )
  258.    {    dprintf4("[k]cbox=[%g %g %g %g]\n",
  259.          fixed2float(cbox_ll.x), fixed2float(cbox_ll.y),
  260.          fixed2float(cbox_ur.x), fixed2float(cbox_ur.y));
  261.     print_ctm("  ", pgs);
  262.    }
  263. #endif
  264.         iwidth = fixed2long(cdim.x) + 2;
  265.         iheight = fixed2long(cdim.y) + 2;
  266.         if (    iwidth != (ushort)iwidth ||
  267.             iheight != (ushort)iheight
  268.            )
  269.           return 0;        /* much too big */
  270.         if ( !penum->dev_cache_set )
  271.            {    /* Set up the memory device for the character cache */
  272.             device *dev = &penum->dev_cache_dev;
  273.             penum->dev_cache_info = mem_mono_device;
  274.             dev->info = (gx_device *)&penum->dev_cache_info;
  275.             dev->is_band_device = 0;
  276.             dev->white = 1;
  277.             dev->black = 1;
  278.             penum->dev_cache_set = 1;
  279.            }
  280.         if ( (cc = gx_alloc_char_bits(dir,
  281.                     (gx_device_memory *)&penum->dev_cache_info,
  282.                     (ushort)iwidth,
  283.                     (ushort)iheight)) == 0 )
  284.           return 0;        /* too big for cache */
  285.         /* The mins handle transposed coordinate systems.... */
  286.         /* Truncate the offsets to avoid artifacts later. */
  287.         cc->offset.x = fixed_ceiling(-min(cbox_ll.x, cbox_ur.x));
  288.         cc->offset.y = fixed_ceiling(-min(cbox_ll.y, cbox_ur.y));
  289. #ifdef DEBUG
  290. if ( gs_debug['k'] )
  291.         dprintf2("[k]offset=[%g %g]\n", fixed2float(cc->offset.x),
  292.              fixed2float(cc->offset.y));
  293. #endif
  294.         if ( !color_is_pure(pgs->dev_color) )    /* can't use cache */
  295.            {    gx_free_cached_char(dir, cc);
  296.             return code;
  297.            }
  298.         if ( (code = gs_gsave(pgs)) < 0 )
  299.            {    gx_free_cached_char(dir, cc);
  300.             return code;
  301.            }
  302.         /* Nothing can go wrong now.... */
  303.         penum->cc = cc;
  304.         cc->code = gs_show_current_char(penum);
  305.         cc->wxy = penum->wxy;
  306.         /* Install the device */
  307.         pgs->device = &penum->dev_cache_dev;
  308.         pgs->device_is_shared = 1;    /* don't deallocate */
  309.         /* Adjust the translation in the graphics context */
  310.         /* so that the character lines up with the cache. */
  311.         gs_translate_to_fixed(pgs, cc->offset.x, cc->offset.y);
  312.         /* Reset the clipping path to match the metrics. */
  313.         clip_box.p.x = clip_box.p.y = 0;
  314.         clip_box.q.x = int2fixed(iwidth);
  315.         clip_box.q.y = int2fixed(iheight);
  316.         if ( (code = gx_clip_to_rectangle(pgs, &clip_box)) < 0 )
  317.           return code;
  318.         gx_set_black(pgs);    /* Set the color to black. */
  319.        }
  320.     penum->width_status = sws_cache;
  321.     return 0;
  322. }
  323.  
  324. /* setcharwidth */
  325. int
  326. gs_setcharwidth(register gs_show_enum *penum, gs_state *pgs, floatp wx, floatp wy)
  327. {    if ( penum->width_status != sws_none )
  328.         return_error(gs_error_undefined);
  329.     gs_distance_transform2fixed(&pgs->ctm, wx, wy, &penum->wxy);
  330.     penum->width_status = sws_no_cache;
  331.     return 0;
  332. }
  333.  
  334. /* setmetrics */
  335. int
  336. gs_setmetrics(register gs_show_enum *penum, gs_state *pgs,
  337.   gs_point *psbxy, gs_point *pwxy)
  338. {    if ( penum->width_status != sws_none )
  339.         return_error(gs_error_undefined);
  340.     if ( psbxy != 0 )
  341.        {    penum->metrics_sb.x = float2fixed(psbxy->x);
  342.         penum->metrics_sb.y = float2fixed(psbxy->y);
  343.         penum->sb_set = 1;
  344.        }
  345.     if ( pwxy != 0 )
  346.        {    penum->metrics_width.x = float2fixed(pwxy->x);
  347.         penum->metrics_width.y = float2fixed(pwxy->y);
  348.         penum->width_set = 1;
  349.        }
  350.     return 0;
  351. }
  352.  
  353. /* ------ Enumerator ------ */
  354.  
  355. /* Do the next step of a show (or stringwidth) operation */
  356. int
  357. gs_show_next(gs_show_enum *penum)
  358. {    return (*penum->continue_proc)(penum);
  359. }
  360.  
  361. /* Continuation procedures */
  362. #define show_fast_move(wxy, pgs)\
  363.   gx_path_add_rel_point_inline(pgs->path, wxy.x, wxy.y)
  364. private int show_update(P1(register gs_show_enum *penum));
  365. private int show_move(P1(register gs_show_enum *penum));
  366. private int show_proceed(P1(register gs_show_enum *penum));
  367. private int show_finish(P1(register gs_show_enum *penum));
  368. private int
  369. continue_show_update(register gs_show_enum *penum)
  370. {    int code = show_update(penum);
  371.     if ( code < 0 ) return code;
  372.     code = show_move(penum);
  373.     if ( code != 0 ) return code;
  374.     return show_proceed(penum);
  375. }
  376. private int
  377. continue_show(register gs_show_enum *penum)
  378. {    return show_proceed(penum);
  379. }
  380.  
  381. /* Update position */
  382. private int
  383. show_update(register gs_show_enum *penum)
  384. {    register gs_state *pgs = penum->pgs;
  385.     /* Update position for last character */
  386.     switch ( penum->width_status )
  387.        {
  388.     case sws_none:
  389.         return_error(gs_error_invalidfont);    /* WRONG */
  390.     case sws_cache:
  391.        {    /* Finish installing the cache entry. */
  392.         cached_char *cc = penum->cc;
  393.         int code;
  394.         /* If the BuildChar procedure did a save and a restore, */
  395.         /* it already undid the gsave in setcachedevice. */
  396.         /* We have to check for this by comparing levels. */
  397.         switch ( pgs->level - penum->level )
  398.            {
  399.         default:
  400.             return_error(gs_error_invalidfont);    /* WRONG */
  401.         case 2:
  402.             code = gs_grestore(pgs);
  403.             if ( code < 0 ) return code;
  404.         case 1:
  405.             ;
  406.            }
  407.         gx_add_cached_char(pgs->font->dir, &penum->dev_cache_info,
  408.                    cc, gx_lookup_fm_pair(pgs));
  409.         if ( !penum->stringwidth_flag && !penum->charpath_flag )
  410.           { /* Copy the bits to the real output device. */
  411.             penum->color_loaded = 0;    /* force gx_color_render */
  412.             code = gs_grestore(pgs);
  413.             if ( code < 0 ) return code;
  414.             return gx_image_cached_char(penum, cc);
  415.           }
  416.        }
  417.     case sws_no_cache: ;
  418.        }
  419.     return gs_grestore(pgs);
  420. }
  421.  
  422. /* Move to next character */
  423. private int
  424. show_move(register gs_show_enum *penum)
  425. {    register gs_state *pgs = penum->pgs;
  426.     if ( penum->add )
  427.         gs_rmoveto(pgs, penum->ax, penum->ay);
  428.     if ( penum->str[penum->index - 1] == penum->wchr )
  429.         gs_rmoveto(pgs, penum->wcx, penum->wcy);
  430.     /* wxy is in device coordinates */
  431.        {    int code = show_fast_move(penum->wxy, pgs);
  432.         if ( code < 0 ) return code;
  433.        }
  434.     /* Check for kerning, but not on the last character. */
  435.     if ( penum->do_kern && penum->index < penum->size )
  436.        {    penum->continue_proc = continue_show;
  437.         return gs_show_kern;
  438.        }
  439.     return 0;
  440. }
  441. /* Process next character */
  442. private int
  443. show_proceed(register gs_show_enum *penum)
  444. {    register gs_state *pgs = penum->pgs;
  445.     byte *str = penum->str;
  446.     uint index;
  447.     cached_fm_pair *pair = 0;
  448.     char_code chr;
  449.     int code;
  450.     penum->color_loaded = 0;
  451. more:    /* Proceed to next character */
  452.     if ( penum->can_cache )
  453.        {    /* Loop with cache */
  454.         if ( pair == 0 )
  455.           pair = gx_lookup_fm_pair(pgs);
  456.         if ( penum->stringwidth_flag )
  457.           while ( (index = penum->index++) != penum->size )
  458.             {    cached_char *cc;
  459.             chr = str[index];
  460.             cc = gx_lookup_cached_char(pgs, pair, chr);
  461.             if ( cc == 0 ) goto no_cache;
  462.             /* Character is in cache. */
  463.             code = show_fast_move(cc->wxy, pgs);
  464.             if ( code ) return code;
  465.             }
  466.         else
  467.           while ( (index = penum->index++) != penum->size )
  468.             {    cached_char *cc;
  469.             chr = str[index];
  470.             cc = gx_lookup_cached_char(pgs, pair, chr);
  471.             if ( cc == 0 ) goto no_cache;
  472.             /* Character is in cache. */
  473.             code = gx_image_cached_char(penum, cc);
  474.             if ( code < 0 ) return code;
  475.             else if ( code > 0 ) goto no_cache;
  476.             if ( penum->slow_show )
  477.                {    penum->wxy = cc->wxy;
  478.                 code = show_move(penum);
  479.                }
  480.             else
  481.                 code = show_fast_move(cc->wxy, pgs);
  482.             if ( code ) return code;
  483.             }
  484.         /* All done. */
  485.         return show_finish(penum);
  486.        }
  487.     else
  488.        {    /* Can't use cache */
  489.         if ( (index = penum->index++) == penum->size )
  490.           {    /* All done. */
  491.             return show_finish(penum);
  492.           }
  493.         chr = str[index];
  494.        }
  495. no_cache:
  496.     /* Character is not cached, client must render it. */
  497.     if ( (code = gs_gsave(pgs)) < 0 ) return code;
  498.     /* Set the charpath flag in the graphics context if necessary, */
  499.     /* so that fill and stroke will add to the path */
  500.     /* rather than having their usual effect. */
  501.     pgs->in_charpath = penum->charpath_flag;
  502.        {    gs_fixed_point cpt;
  503.         gx_path *ppath = pgs->path;
  504.         if ( (code = gx_path_current_point_inline(ppath, &cpt)) < 0 )
  505.             return code;
  506.         cpt.x -= pgs->ctm.tx_fixed;
  507.         cpt.y -= pgs->ctm.ty_fixed;
  508.         gs_setmatrix(pgs, &pgs->char_tm);
  509.         cpt.x += pgs->ctm.tx_fixed;
  510.         cpt.y += pgs->ctm.ty_fixed;
  511.         if ( !penum->stringwidth_flag && !penum->charpath_flag )
  512.           { /* Round the translation in the graphics state. */
  513.             /* This helps prevent rounding artifacts later. */
  514.             cpt.x = fixed_rounded(cpt.x);
  515.             cpt.y = fixed_rounded(cpt.y);
  516.           }
  517.         gs_translate_to_fixed(pgs, cpt.x, cpt.y);
  518.         gs_newpath(pgs);
  519.         gx_path_add_point(ppath, pgs->ctm.tx_fixed,
  520.                   pgs->ctm.ty_fixed);
  521.        }
  522.     penum->width_status = sws_none;
  523.     penum->width_set = penum->sb_set = 0;
  524.     penum->continue_proc = continue_show_update;
  525.     /* Try using the build procedure in the font. */
  526.     /* < 0 means error, 0 means success, 1 means failure. */
  527.        {    gs_font *pfont = pgs->font;
  528.         code = (*pfont->build_char_proc)(penum, pgs, pfont, chr, pfont->build_char_data);
  529.         if ( code < 0 ) return_error(code);
  530.         if ( code == 0 )
  531.            {    code = show_update(penum);
  532.             if ( code < 0 ) return code;
  533.             penum->color_loaded = 0;
  534.             code = show_move(penum);
  535.             if ( code ) return code;
  536.             goto more;
  537.            }
  538.        }
  539.     return gs_show_render;
  540. }
  541.  
  542. /* Finish show or stringwidth */
  543. private int
  544. show_finish(register gs_show_enum *penum)
  545. {    register gs_state *pgs = penum->pgs;
  546.     int code;
  547.     if ( !penum->stringwidth_flag ) return 0;
  548.     /* Save the accumulated width before returning, */
  549.     /* and undo the extra gsave. */
  550.     code = gs_currentpoint(pgs, &penum->width);
  551.     if ( code < 0 ) return code;
  552.     return gs_grestore(pgs);
  553. }
  554.  
  555. /* Return the current character for rendering. */
  556. char_code
  557. gs_show_current_char(gs_show_enum *penum)
  558. {    return penum->str[penum->index - 1];
  559. }
  560.  
  561. /* Return the just-displayed character for kerning. */
  562. char_code
  563. gs_kshow_previous_char(gs_show_enum *penum)
  564. {    return penum->str[penum->index - 1];
  565. }
  566.  
  567. /* Return the about-to-be-displayed character for kerning. */
  568. char_code
  569. gs_kshow_next_char(gs_show_enum *penum)
  570. {    return penum->str[penum->index];
  571. }
  572.  
  573. /* Return the accumulated width for stringwidth. */
  574. void
  575. gs_show_width(gs_show_enum *penum, gs_point *ppt)
  576. {    *ppt = penum->width;
  577. }
  578.  
  579. /* Return the charpath flag. */
  580. int
  581. gs_show_in_charpath(gs_show_enum *penum)
  582. {    return penum->charpath_flag;
  583. }
  584.  
  585. /* ------ Internal routines ------ */
  586.  
  587. /* Initialize a show enumerator */
  588. private int
  589. show_setup(register gs_show_enum *penum, gs_state *pgs, char *str)
  590. {    int code;
  591.     gs_font *pfont = pgs->font;
  592.     penum->pgs = pgs;
  593.     penum->level = pgs->level;
  594.     penum->str = (byte *)str;    /* avoid signed chars */
  595.     penum->wchr = no_chr;
  596.     penum->add = 0;
  597.     penum->do_kern = 0;
  598.     penum->charpath_flag = 0;
  599.     penum->stringwidth_flag = 0;
  600.     penum->dev_cache_set = 0;
  601.     penum->index = 0;
  602.     penum->continue_proc = continue_show;
  603.     if ( (penum->is_composite = pfont->FontType == ft_composite) )
  604.        {    gs_font *rfont = pgs->font;
  605.         penum->fstack[0] = rfont;
  606.         penum->fdepth = 0;
  607.         penum->pfont =
  608.           rfont->data.type0_data.FDepVector[rfont->data.type0_data.Encoding[0]];
  609.        }
  610.     if ( !pgs->char_tm_valid )
  611.        {    /* Compute combined transformation */
  612.         gs_make_identity(&pgs->char_tm);    /* make sure type */
  613.                     /* fields are set in char_tm! */
  614.         code = gs_matrix_multiply(&pgs->font->FontMatrix,
  615.                       &ctm_only(pgs), &pgs->char_tm);
  616.         if ( code < 0 ) return code;
  617.         pgs->char_tm_valid = 1;
  618.        }
  619.     if ( penum->can_cache =    /* no skewing or non-rectangular rotation */
  620.         (is_fzero2(pgs->char_tm.xy, pgs->char_tm.yx) ||
  621.          is_fzero2(pgs->char_tm.xx, pgs->char_tm.yy)) )
  622.        {    gs_fixed_rect cbox;
  623.         gx_cpath_box_for_check(pgs->clip_path, &cbox);
  624.         penum->cxmin = fixed2int_var(cbox.p.x);
  625.         penum->cymin = fixed2int_var(cbox.p.y);
  626.         penum->cxmax = fixed2int_var(cbox.q.x);
  627.         penum->cymax = fixed2int_var(cbox.q.y);
  628.         penum->ftx = (int)fixed2long(float2fixed(pgs->char_tm.tx) - pgs->ctm.tx_fixed);
  629.         penum->fty = (int)fixed2long(float2fixed(pgs->char_tm.ty) - pgs->ctm.ty_fixed);
  630.        }
  631.     return 0;
  632. }
  633.